<?php

require_once 'Validator.php';

class NumericValidator extends Validator
{
	protected $min;
	protected $max;
	
	public function __construct($required, $min, $max)
	{
		$this->required = $required;
		$this->min = min($min, $max);
		$this->max = max($min, $max);		
	}
	
	public function validate(Validatable $field)
	{
		if(!parent::validate($field))
		{
			return false;			
		}
		
		$value = $field->getValue();
		
		if(!is_numeric($value) || $value < $this->min || $value > $this->max)
		{
			$field->setError('moet een getal tussen '.$this->min.' en '.$this->max.' zijn');
			return false;
		}
		return true;
	}
	
}